package cn.cscamp.middleware.loadbalancer;

import org.springframework.http.HttpHeaders;
import org.springframework.http.client.reactive.ClientHttpConnector;
import org.springframework.http.codec.ClientCodecConfigurer;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
import org.springframework.web.reactive.function.client.ExchangeFunction;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.UriBuilderFactory;

import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

public class RetryWebClientFactory implements WebClient.Builder {

    private final WebClient.Builder builder;

    public RetryWebClientFactory(WebClient.Builder builder) {
        this.builder = builder;
    }

    @Override
    public WebClient.Builder baseUrl(String s) {
        return builder.baseUrl(s);
    }

    @Override
    public WebClient.Builder defaultUriVariables(Map<String, ?> map) {
        return builder.defaultUriVariables(map);
    }

    @Override
    public WebClient.Builder uriBuilderFactory(UriBuilderFactory uriBuilderFactory) {
        return builder.uriBuilderFactory(uriBuilderFactory);
    }

    @Override
    public WebClient.Builder defaultHeader(String s, String... strings) {
        return builder.defaultHeader(s, strings);
    }

    @Override
    public WebClient.Builder defaultHeaders(Consumer<HttpHeaders> consumer) {
        return builder.defaultHeaders(consumer);
    }

    @Override
    public WebClient.Builder defaultCookie(String s, String... strings) {
        return builder.defaultCookie(s, strings);
    }

    @Override
    public WebClient.Builder defaultCookies(Consumer<MultiValueMap<String, String>> consumer) {
        return builder.defaultCookies(consumer);
    }

    @Override
    public WebClient.Builder defaultRequest(Consumer<WebClient.RequestHeadersSpec<?>> consumer) {
        return builder.defaultRequest(consumer);
    }

    @Override
    public WebClient.Builder filter(ExchangeFilterFunction exchangeFilterFunction) {
        return builder.filter(exchangeFilterFunction);
    }

    @Override
    public WebClient.Builder filters(Consumer<List<ExchangeFilterFunction>> consumer) {
        return builder.filters(consumer);
    }

    @Override
    public WebClient.Builder clientConnector(ClientHttpConnector clientHttpConnector) {
        return builder.clientConnector(clientHttpConnector);
    }

    @Override
    public WebClient.Builder codecs(Consumer<ClientCodecConfigurer> consumer) {
        return builder.codecs(consumer);
    }

    @Override
    public WebClient.Builder exchangeStrategies(ExchangeStrategies exchangeStrategies) {
        return builder.exchangeStrategies(exchangeStrategies);
    }

    @Override
    public WebClient.Builder exchangeStrategies(Consumer<ExchangeStrategies.Builder> consumer) {
        return builder.exchangeStrategies(consumer);
    }

    @Override
    public WebClient.Builder exchangeFunction(ExchangeFunction exchangeFunction) {
        return builder.exchangeFunction(exchangeFunction);
    }

    @Override
    public WebClient.Builder apply(Consumer<WebClient.Builder> consumer) {
        return builder.apply(consumer);
    }

    @Override
    public WebClient.Builder clone() {
        return builder.clone();
    }

    @Override
    public WebClient build() {
        return builder.build();
    }
}
